﻿
using System;
using System.Collections.Generic;
using SanguoSharp.Server.Characters;
namespace SanguoSharp.Server
{
    public class Character
    {
        private Player player;
        private CharacterType type;
        private bool cannotmiss;

        public bool CannotMiss
        {
            get { return cannotmiss; }
            set { cannotmiss = value; }
        }

        protected Game Game
        {
            get { return player.Game; }
        }
        public Player Player
        {
            get { return player; }
        }
        public CharacterType Type
        {
            get { return type; }
        }


        public virtual int MaxLifePoints
        {
            get { return 4; }
        }
        public virtual int InitialCardCount
        {
            get { return MaxLifePoints; }
        }
        public virtual int MaxCardCount
        {
            get { return player.LifePoints; }
        }
        public virtual int DistanceIn
        {
            get { return 0; }
        }
        public virtual int DistanceOut
        {
            get { return 0; }
        }
        public virtual int KillPower
        {
            get { return 1; }
        }
        public virtual int BeerPower
        {
            get { return 1; }
        }
        public virtual bool UnlimitedBangs
        {
            get { return false; }
        }
        public virtual bool TakesDeadPlayersCards
        {
            get { return false; }
        }

        protected Character(Player player, CharacterType type)
        {
            this.player = player;
            this.type = type;
        }

        protected void OnUsedAbility()
        {
            player.Game.Session.EventManager.OnPlayerUsedAbility(player, type);
        }
        protected void OnUsedAbility(Player targetPlayer)
        {
            player.Game.Session.EventManager.OnPlayerUsedAbility(player, type, targetPlayer);
        }

        public virtual bool HasCardEffect(Card card)
        {
            return true;
        }
        public virtual bool IsMissed(Card card)
        {
            return card.Type == CardType.闪;
        }
        public virtual bool IsBang(Card card)
        {
            return card.Type == CardType.杀;
        }
        public virtual bool CanPlayCard(CardType card)
        {
            return true;
        }

        public virtual void Draw()
        {
            throw new BadUsageException();
        }
        public virtual void PlayCard(Card card)
        {
            card.Play();
        }
        public virtual void UseAbility()
        {
        }
        public virtual void CheckDeck(Card causedBy, CheckDeckMethod checkMethod, CardResultMethod resultMethod)
        {
            Card checkedCard = player.Game.GameTable.CheckDeck();
            bool result = checkMethod(checkedCard);
            Game.Session.EventManager.OnPlayerCheckedDeck(player, checkedCard, causedBy, result);
            resultMethod(causedBy, result);
        }


        public virtual void CheckDeck(Player causedBy, CheckDeckMethod checkMethod, PlayerResultMethod resultMethod)
        {
            Card checkedCard = player.Game.GameTable.CheckDeck();
            bool result = checkMethod(checkedCard);
            Game.Session.EventManager.OnPlayerCheckedDeck(player, checkedCard, causedBy, result);
            resultMethod(causedBy, result);
        }
        public virtual void CheckMissed(CardResultMethod resultMethod)
        {
            throw new BadUsageException();
        }

        public virtual void OnHit(int hitPoints, Player causedBy)
        {
        }
        public virtual void OnEmptyHand()
        {
        }
        public virtual void OnPlayerDied(Player player)
        {
        }
        public virtual void OnTurnStarted()
        {
        }
        public virtual void OnPlayContinue()
        {
        }
        public virtual void OnTurnEnded()
        {
        }
        public virtual void OnPlayedCard(Card card)
        {
        }
        public virtual void OnRespondedWithCard(Card card)
        {
        }
        public virtual bool SavePlayer()
        {
            return false;
        }

        public static Character GetCharacter(Player player, CharacterType type)
        {
            switch (type)
            {
                case CharacterType.BartCassidy:
                    return new BartCassidy(player);
                case CharacterType.BlackJack:
                    return new BlackJack(player);
                case CharacterType.CalamityJanet:
                    return new CalamityJanet(player);
                case CharacterType.ElGringo:
                    return new ElGringo(player);
                case CharacterType.JesseJones:
                    return new JesseJones(player);
                case CharacterType.Jourdonnais:
                    return new Jourdonnais(player);
                case CharacterType.KitCarlson:
                    return new KitCarlson(player);
                case CharacterType.LuckyDuke:
                    return new LuckyDuke(player);
                case CharacterType.PaulRegret:
                    return new PaulRegret(player);
                case CharacterType.PedroRamirez:
                    return new PedroRamirez(player);
                case CharacterType.RoseDoolan:
                    return new RoseDoolan(player);
                case CharacterType.SidKetchum:
                    return new SidKetchum(player);
                case CharacterType.SlabTheKiller:
                    return new SlabTheKiller(player);
                case CharacterType.陆逊:
                    return new 陆逊(player);
                case CharacterType.VultureSam:
                    return new VultureSam(player);
                case CharacterType.WillyTheKid:
                    return new WillyTheKid(player);
                case CharacterType.ApacheKid:
                    return new ApacheKid(player);
                case CharacterType.BelleStar:
                    return new BelleStar(player);
                case CharacterType.BillNoface:
                    return new BillNoface(player);
                case CharacterType.ChuckWengam:
                    return new ChuckWengam(player);
                case CharacterType.DocHolyday:
                    return new DocHolyday(player);
                case CharacterType.ElenaFuente:
                    return new ElenaFuente(player);
                case CharacterType.GregDigger:
                    return new GregDigger(player);
                case CharacterType.HerbHunter:
                    return new HerbHunter(player);
                case CharacterType.JoseDelgado:
                    return new JoseDelgado(player);
                case CharacterType.MollyStark:
                    return new MollyStark(player);
                case CharacterType.PatBrennan:
                    return new PatBrennan(player);
                case CharacterType.PixiePete:
                    return new PixiePete(player);
                case CharacterType.SeanMallory:
                    return new SeanMallory(player);
                case CharacterType.TequilaJoe:
                    return new TequilaJoe(player);
                case CharacterType.VeraCuster:
                    return new VeraCuster(player);
                default:
                    throw new ArgumentOutOfRangeException("type");
                //case CharacterType.: return new (player);
            }
        }
    }
}